package edu.sdufe.map.hashMap;



import java.util.*;

/**
 * @author wang'ji'cheng
 * @date 2025/7/26
 */
public class Demo2 {
    public static void main(String[] args) {

        HashMap<String, Integer> map = new HashMap<>();
        //数组用来存放景点
        String[] arr = {"A","B","C","D"};
        //模拟学生随机投票
        Random random = new Random();
        ArrayList<String> list = new ArrayList<>();
        for (int i = 0; i < 80 ; i++) {
            int index = random.nextInt(arr.length);
            list.add(arr[index]);
        }
        for (String string : list) {
            if(map.containsKey(string)){
                Integer count = map.get(string);
                count++;
                map.put(string,count);
            }else {
                map.put(string,1);
            }
        }
        System.out.println(map);

      int max=0;
        for (Integer value : map.values()) {
            if(value>max){
                max = value;
            }
        }
        for (Map.Entry<String, Integer> entry : map.entrySet()) {
            if(entry.getValue()==max){
                System.out.println(entry.getKey());
            }
        }

    }

}
